<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改栏目')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-column-edit" th:object="${column}">
        <input name="id" type="hidden" th:field="*{id}"/>
        <input id="treeId" name="parentId" type="hidden" th:field="*{pId}"/>
        <div class="form-group">
            <label class="col-sm-3 control-label">上级栏目：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectDeptTree()" id="treeName"
                           th:readonly="readonly" th:field="*{upColumnName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">栏目名称：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="name" id="name" th:field="*{name}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">外部链接：</label>
            <div class="col-sm-8">
                <label class="radio-box"> <input type="radio" th:field="*{outLink}" name="outLink" value="0"/> 是</label>
                <label class="radio-box"> <input type="radio" th:field="*{outLink}" name="outLink" value="1"/> 否
                </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">栏目标识：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="columnFlag" id="columnFlag" th:field="*{columnFlag}"
                       required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">外部链接地址：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="href" id="href" th:field="*{href}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label  is-required">排序：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="sort" th:field="*{sort}" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否显示：</label>
            <div class="col-sm-9">
                <div class="radio-box" th:each="dict : ${@dict.getType('cms_show_hide')}">
                    <input type="radio" th:id="${dict.dictCode}" name="display" th:value="${dict.dictValue}"
                           th:field="*{display}" th:checked="${dict.default}">
                    <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <textarea type="text" name="remark" class="form-control" th:rows="8" th:field="*{remark}"
                          placeholder="请输入文本"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript" th:inline="javascript">
    var prefix = ctx + "cms/column";
    $(function () {
        var outLink = $('input[name="outLink"]:checked').val();
        columnVisible(outLink);

        /*外部链接单击选择事件*/
        $('input[name="outLink"]').on('ifChecked', function (event) {
            var outLink2 = $(event.target).val();
            columnVisible(outLink2);
        });
    })

    function columnVisible(outLink) {
        if (outLink == "0") {
            $("#columnFlag").parents(".form-group").hide();
            $("#href").parents(".form-group").show();
        } else if (outLink == "1") {
            $("#columnFlag").parents(".form-group").show();
            $("#href").parents(".form-group").hide();
        }
    }

    function submitHandler() {
        if ($.validate.form()) {
            //如果不是外部链接，清空外部链接地址值
            if ($("#columnFlag").val() != '') {
                $("#href").val('');
            }
            $.operate.save(prefix + "/addSave", $('#form-column-edit').serializeArray());
        }
    }

    /*栏目管理-新增-选择父栏目树*/
    function selectDeptTree() {
        var options = {
            title: '栏目选择',
            width: "380",
            url: prefix + "/selectColumnTree?columnId=" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    /*上级栏目树 确定按钮执行函数*/
    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }
</script>
</body>
</html>
